/// 数据模型

use serde::{Deserialize, Serialize};


#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Board {
    pub id: String,
    pub dimensions: (f64, f64), // (width, height)
    pub thickness: f64,
    pub components: Vec<Component>,
}



#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
pub enum ComponentType {
    Hole,       // 孔
    Slot,       // 槽
    Pocket,     // 口袋
    Contour,    // 轮廓
    Engraving,  // 雕刻
    Custom(String),
}

#[derive(Debug, Clone)]
pub struct Toolpath {
    pub tool: Tool,
    pub operations: Vec<Operation>,
}

#[derive(Debug, Clone)]
pub struct Tool {
    pub diameter: f64,
    pub tool_type: ToolType,
    pub feed_rate: f64,
    pub plunge_rate: f64,
}

#[derive(Debug, Clone)]
pub enum ToolType {
    Drill,
    EndMill,
    BallNose,
    VBit,
}

#[derive(Debug, Clone)]
pub enum Operation {
    MoveTo((f64, f64)),
    LinearCut((f64, f64)),
    ArcCut((f64, f64), (f64, f64), bool), // 终点, 圆心, 顺时针?
    Drill(f64), // 钻孔深度
    Plunge(f64),
}




#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Component {
    pub id: String,
    pub component_type: ComponentType,
    pub position: (f64, f64),
    pub rotation: f64,
    pub parameters: ComponentParameters,
}

// 组件参数枚举
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum ComponentParameters {
    Hole(HoleParameters),
    Slot(SlotParameters),
    Pocket(PocketParameters),
    Contour(ContourParameters),
    Engraving(EngravingParameters),
    Custom(CustomParameters),
}

// 孔加工参数
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct HoleParameters {
    pub diameter: f64,
    pub depth: Option<f64>, // 可选，如果未指定则使用板件厚度
    pub countersink: Option<f64>, // 沉头孔直径
    pub thread_type: Option<String>, // 螺纹类型
}

// 槽加工参数
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SlotParameters {
    pub width: f64,
    pub length: f64,
    pub depth: Option<f64>,
    pub corner_radius: Option<f64>, // 拐角半径
    pub orientation: Option<f64>, // 方向（角度）
}

// 口袋加工参数
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PocketParameters {
    pub width: f64,
    pub height: f64,
    pub depth: f64,
    pub corner_radius: Option<f64>,
    pub island: Option<bool>, // 是否有岛
}

// 轮廓加工参数
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ContourParameters {
    pub path: Vec<(f64, f64)>, // 轮廓点坐标
    pub depth: f64,
    pub tolerance: f64, // 加工精度
}

// 雕刻加工参数
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct EngravingParameters {
    pub text: Option<String>, // 雕刻文本
    pub depth: f64,
    pub font_size: Option<f64>,
    pub font_name: Option<String>,
}

// 自定义加工参数
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CustomParameters {
    pub type_name: String, // 自定义类型标识
    // pub params: serde_json::Value, // 保留灵活性
}